package com.bluezone.dec.common;

import lombok.Data;

@Data
public class JsonResult {

    private Integer code;
    private Object data;
    private String msg;

    public JsonResult() {
    }

    public JsonResult ok() {
        return new JsonResult(CodeEnum.OK.getCode(), CodeEnum.OK.getMsg());
    }

    public JsonResult ok(Object data) {
        return new JsonResult(CodeEnum.OK.getCode(), CodeEnum.OK.getMsg(), data);
    }

    public JsonResult error() {
        return new JsonResult(CodeEnum.DB_OPER_FAIL.getCode(), CodeEnum.DB_OPER_FAIL.getMsg());
    }

    public JsonResult none() {
        return new JsonResult(CodeEnum.NO_RECORD_NOW.getCode(), CodeEnum.NO_RECORD_NOW.getMsg());
    }

    public JsonResult exist() {
        return new JsonResult(CodeEnum.RECORD_ALREADY_EXIST.getCode(), CodeEnum.RECORD_ALREADY_EXIST.getMsg());
    }

    public JsonResult paramsError() {
        return new JsonResult(CodeEnum.PARAMS_ERROR.getCode(), CodeEnum.PARAMS_ERROR.getMsg());
    }

    public JsonResult sendCode(CodeEnum code) {
        return new JsonResult(code.getCode(), code.getMsg());
    }

    public JsonResult sendData(CodeEnum code, Object data) {
        return new JsonResult(code.getCode(), code.getMsg(), data);
    }

    public JsonResult(Integer code) {
        this.setCode(code);
    }

    public JsonResult(Integer code, String msg) {
        this.setCode(code);
        this.setMsg(msg);
    }

    public JsonResult(Integer code, String msg, Object data) {
        this.setCode(code);
        this.setMsg(msg);
        this.setData(data);
    }

}
